﻿using System;
using System.Web;
using System.Web.Configuration;
using visinia.SmartEngine.Cache;

namespace visinia.SmartEngine
{
    /// <summary>
    /// WebRoots is used for easy access to diffrent paths to site
    /// </summary>
    public class WebRoots
    {

        /// <summary>
        /// Returns the relative path to web root
        /// </summary>
        public static string GetRelativeWebRoot
        {
            get
            {
                string root = (string)DataCache.GetCache("visinia_RelativeWebRoot");
                if (root == null)
                {
                    root = VirtualPathUtility.ToAbsolute(WebConfigurationManager.AppSettings["visinia.VirtualRoot"]);
                    DataCache.SetCache("visinia_RelativeWebRoot", root);
                }
                return root;
            }
        }

        /// <summary>
        /// Returns the path to web root
        /// </summary>
        public static string GetWebRoot
        {
            get
            {
                string root = (string)DataCache.GetCache("visinia_WebRoot");
                if (root == null)
                {
                    root = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + GetRelativeWebRoot;
                    DataCache.SetCache("visinia_WebRoot", root);
                }
                return root;
            }
        }

        /// <summary>
        /// Returns the path to the admin folder
        /// </summary>
        public static string GetAdminRoot
        {
            get { return GetRelativeWebRoot + "Admin/"; }
        }

        /// <summary>
        /// Returns the path to the admin's pages folder
        /// </summary>
        public static string GetAdminPagesRoot
        {
            get { return GetAdminRoot + "Pages/"; }
        }

        /// <summary>
        /// Returns the path to the admin/scripts folder
        /// </summary>
        public static string GetAdminScriptsRoot
        {
            get { return GetAdminRoot + "Scripts/"; }
        }
      
        /// <summary>
        /// Returns the path to the Bin folder
        /// </summary>
        public static string GetBinRoot
        {
            get{return GetRelativeWebRoot + "Bin/";}            
        }

        /// <summary>
        /// Returns the path to the js folder
        /// </summary>
        public static string GetJsRoot
        {
            get { return GetRelativeWebRoot + "js/"; }
        }

        /// <summary>
        /// Returns the path to the modules folder
        /// </summary>
        public static string GetModulesRoot
        {
            get{return GetRelativeWebRoot + "Modules/";}            
        }

        /// <summary>
        /// Returns the path to the themes root folder
        /// </summary>
        public static string GetThemesRoot
        {
            get{return GetRelativeWebRoot + "Themes/";}            
        }

        /// <summary>
        /// Returns the path to the resources folder
        /// </summary>
        public static string GetResourcesRoot
        {
            get{return GetRelativeWebRoot + "Resources/";}             
        }

        /// <summary>
        /// Returns the path to the Installation folder
        /// </summary>
        public static string GetInstallRoot
        {
            get{return GetRelativeWebRoot + "Install/";}            
        }

        /// <summary>
        /// Returns the path to the UnInstallation folder
        /// </summary>
        public static string GetUnInstallRoot
        {
            get{return GetInstallRoot + "UnInstall/";}             
        }
                
        /// <summary>
        /// Returns the path to the Temporary Installation folder (deleted after every installation completion)
        /// </summary>
        public static string GetInstallTemporaryRoot
        {
            get{return GetInstallRoot + "TempInstallFolder/";}             
        }
    }
}
